package com.wsd.smartcarwasher.controller;

import com.wsd.smartcarwasher.domain.SysDic;
import com.wsd.smartcarwasher.domain.UserInfo;
import com.wsd.smartcarwasher.service.SysDicService;
import com.wsd.smartcarwasher.util.ReturnUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(
        tags = {"PC-系统配置"}
)
@Controller
@CrossOrigin
public class SysDicController {
    @Resource
    private SysDicService sysDicService;


    @ApiOperation(
            value = "查询所有 ",
            notes = "查询所有",
            produces = "application/json",
            response = SysDic.class
    )
    @RequestMapping(
            value = {"/sys/getAllSysDic"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap getAllSysDic() {
        return  ReturnUtil.Success("获取所有系统配置成功",this.sysDicService.getAllSysDic());
    }

    @ApiOperation(
            value = "修改 ",
            notes = "修改",
            produces = "application/json",
            response = SysDic.class
    )
    @RequestMapping(
            value = {"/sys/updateSysDic"},
            method = {RequestMethod.POST},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap updateSysDic(@RequestBody SysDic sysDic ) {
        int rows = this.sysDicService.upDateByCode(sysDic);
        if(rows>0){
            return  ReturnUtil.Success("修改成功");
        }
        return  ReturnUtil.Error("修改失败");
    }


    @ApiOperation(
            value = "根据code查询 ",
            notes = "根据code查询",
            produces = "application/json",
            response = SysDic.class
    )
    @RequestMapping(
            value = {"/sys/getSysDicByCode"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap getSysDicByCode(@RequestParam Integer code ) {
        return  ReturnUtil.Success("查询成功",sysDicService.getByCode(code));
    }
}


